package com.qf.day08.homework.book;

/**
 * 写使用BookServcie接口的测试代码
 */
public class Demo01 {
    public static void main(String[] args) {

        BookService bookService = new BookServiceImpl();
        Book book = new Book();
        book.setBookName("西游记");
        book.setBookAuthor("吴承恩");
        book.setLocation("AAA");
//        book.setBookId(1);
        // 测试添加book方法
        bookService.addBook(book);

        // 查询book
        Book[] books = bookService.selectAll();
        for (int i = 0; i < books.length; i++) {
            System.out.println(books[i]);
        }
        // 查询一本书
        Book book2 = bookService.selectOne(0);
        System.out.println(book2);

        System.out.println("=========================================");

        // 测试修改book方法
        Book book1 = new Book();
        book1.setBookId(0);
//        book1.setBookName("西游");
//        book1.setBookAuthor("吴承恩");
        book1.setLocation("BBB");
        bookService.updateBook(book1);

        System.out.println(bookService.selectOne(0));

        bookService.addBook(new Book("红楼梦","曹雪芹","CCC"));

        // 删除book
        bookService.deleteBook(0);

        books = bookService.selectAll();
        for (int i = 0; i < books.length; i++) {
            System.out.println(books[i]);
        }

    }
}
